package com.gitee.gphomework.pattern.commandpattern.invoker;

import com.gitee.gphomework.pattern.commandpattern.command.CwdCommand;
import com.gitee.gphomework.pattern.commandpattern.command.IFtpCommand;
import com.gitee.gphomework.pattern.commandpattern.command.PortCommand;
import com.gitee.gphomework.pattern.commandpattern.command.QuitCommand;
import com.gitee.gphomework.pattern.commandpattern.command.RetrCommand;
import com.gitee.gphomework.pattern.commandpattern.command.SizeCommand;
import com.gitee.gphomework.pattern.commandpattern.receiver.FtpCmdReceiver;

import java.util.ArrayList;
import java.util.List;

/**
 * Created on 2020/3/17
 * Title: Ftp客户端
 * Description: Ftp客户端类型
 * Copyright: Copyright(c) 2020
 * Company:
 *
 * @author yifeng
 */
public class FtpActiveModeClient extends FtpBaseClient {

    private List<IFtpCommand> commands;

    public FtpActiveModeClient() {
        super();
        commands = new ArrayList<>(5);
        commands.add(new CwdCommand(FtpCmdReceiver.getInstance()));
        commands.add(new SizeCommand(FtpCmdReceiver.getInstance()));
        commands.add(new PortCommand(FtpCmdReceiver.getInstance()));
        commands.add(new RetrCommand(FtpCmdReceiver.getInstance()));
        commands.add(new QuitCommand(FtpCmdReceiver.getInstance()));
    }

    /**
     * 主动模式下载文件
     */
    public void activeModeDownload() {
        initFtpConnection();
        commands.forEach(IFtpCommand::execute);
    }

}
